/*
* @file model/infoRevise.js
*  个人设置/信息修改
* @author
*
*/
import { routerRedux } from 'dva/router';
import api from '../api';
import { notification } from 'antd';
export default{
	namespace:"infoedit",
	state:{

	},
	subscriptions:{
		setup({dispatch,history}) {
			history.listen(({pathname,query}) => {
				if( pathname === '/personalSettings/infoRevise' ){
					dispatch({
						type: 'getInfoList',
						payload: query
					})
				}
			})
		}
	},
	effects:{
		*getInfoList({payload:query},{call,put}){
			const response = yield call(api.getinfo, query);
			yield put({
				type: 'getListSuccess',
				payload: response ,
			})
		},
		*saveInfo({ payload }, { call, put }) {
			const response = yield call(api.saveInfo,payload );
			// console.log('response>>>>',response)
			yield put({
				type: 'saveSuccess',
				payload: { response },
			});
		},
	},
	reducers:{
		getListSuccess(state, {payload}) {
			const {data} = payload
			// console.log('data>>>>>',data)
			const status=data ? true:false
			return {
				...state,
				status,
				userinfo:data,
			}
		},
		saveSuccess(state, action) {
			const { payload: { response } } = action;
			notification['success']({
		   message: '保存成功',
		  });
			return {
				...state,
			};
		},
	}
}